//Ta Duc Viet
//Nhan 2 ma tran 
#include <iostream>
#include <iomanip>
using namespace std;

void Nhap_Ma_Tran ( float **, const int, const int);// Nhap ma tran, so dong, so cot
void Nhan_Ma_Tran ( float **KQ, float **a, float **b, const int, const int, const int);
//Nhan 2 ma tran a, b dc ma tran KQ
void In_Ma_Tran ( float **, const int, const int);
const int row_1 = 2;
const int col_1 = 2;
const int row_2 = 2;
const int col_2 = 2;
int main(){
	float **a, **b, **KQ;
	a = new float *[row_1];
	for ( int i = 0; i < row_1; i++){
		a[i] = new float [col_1];
	}
	b = new float *[row_2];
	for ( int i = 0; i < row_2; i++){
		b[i] = new float [col_2];
	}
	int row_3 = row_1;
	int col_3 = col_2;
	KQ = new float *[row_3];
	for ( int i = 0; i < row_3; i++){
		KQ[i] = new float [col_3];
	}
	for( int i = 0; i < row_3; i++){
		for( int j = 0; j < col_3; j++){
			KQ[i][j] = 0;
		}
	}
	cout << "INPUT FIRST (" << row_1 << "x" << col_1 << ") MATRIX" << endl;
	Nhap_Ma_Tran (a, row_1, col_1);
	cout << "INPUT SECOND (" << row_2 << "x" << col_2 << ") MATRIX:" << endl;
	Nhap_Ma_Tran (b, row_2, col_2);
	Nhan_Ma_Tran (KQ, a, b, row_3, row_2, col_3);
	cout << endl;
	In_Ma_Tran (a, row_1, col_1);
	cout << "TIMES" << endl;
	In_Ma_Tran (b, row_2, col_2);
	cout << "EQUALS" << endl;
	In_Ma_Tran (KQ, row_3, col_3);
	cout << endl;
	system("pause");
	return 0;
}
////////////////////////////////////////////////////////////////////////////////////
void Nhap_Ma_Tran ( float **mang, const int row, const int col){
	for ( int i = 0; i < row; i++){
		cout << "Type in " << col << " values for row  " << i + 1 << " separated by spaces:";
		for ( int j = 0; j < col; j++){
			cin >> mang[i][j];
		}
	}
}
void In_Ma_Tran ( float ** mang, const int row, const int col){
	for ( int i = 0; i < row; i++){
		for ( int j = 0; j < col; j++){
			cout << setw(5) << mang[i][j] << "    ";
		}
		cout << endl;
	}
}
void Nhan_Ma_Tran ( float **KQ, float **a, float **b, const int row_3, const int row_2, const int col_3){
	for( int i = 0; i < row_3; i++){
		for( int j = 0; j < col_3; j++){
			for( int u = 0 ; u < row_2; u++){
				KQ[i][j] = KQ[i][j] + a[i][u] * b[u][j];
			}
		}
	}
}
